<%@ include file="/en/jsp/static.jsp" %>
<%@ page import="java.util.*,linuxbox.reservation.logic.*,linuxbox.util.StringUtil" %>

<%@ taglib uri="/linuxbox/Resource.tld" prefix="Resource" %>
<%@ taglib uri="/linuxbox/common.tld" prefix="Common" %>

<%
  int RESOURCEID = -1;
  int RESOURCECATID = -1;
  int VIEW_MINE = 0;
  int VIEW_ALL = 0;
  String SORTBY = "fromtime";
  boolean isAdminUser = false;

  Calendar currentDate = (Calendar)session.getAttribute("currentDate");
  if ( currentDate == null)
  {
    currentDate = Calendar.getInstance(sec.getTimeZone());
    session.setAttribute("currentDate",currentDate);
  }
  String VIEW_FORMAT = (String)session.getAttribute("resv.VIEW_FORMAT");
  if ( VIEW_FORMAT == null || VIEW_FORMAT.length() == 0
    || ( VIEW_FORMAT.compareTo("day") != 0
       && VIEW_FORMAT.compareTo("week") != 0
       && VIEW_FORMAT.compareTo("month") != 0) )
  {
    VIEW_FORMAT = sec.getConfigString("reservation", "General", "Default View");
    session.setAttribute("resv.VIEW_FORMAT", VIEW_FORMAT);
  }

  long prevTime = 0, nextTime = 0;
  String title;
  Calendar tmpDay = (Calendar)currentDate.clone();
  if (VIEW_FORMAT.compareTo("month") == 0)
  {
    tmpDay.add(Calendar.MONTH, -1);
    prevTime = tmpDay.getTime().getTime();
    tmpDay.add(Calendar.MONTH, 2);
    nextTime = tmpDay.getTime().getTime();
    title = StringUtil.getDateTimeFormatString(sec.getTimeZone(), BoxStatic.MONTH_YEAR_FORMAT, currentDate.getTime());
  }
  else if (VIEW_FORMAT.compareTo("week") == 0)
  {
    tmpDay.add(Calendar.WEEK_OF_YEAR, -1);
    prevTime = tmpDay.getTime().getTime();
    tmpDay.add(Calendar.WEEK_OF_YEAR, 2);
    nextTime = tmpDay.getTime().getTime();
    title = linuxbox.calendar.logic.BoxCalendar.getWeekRangeString(currentDate);
  }
  else
  {
    tmpDay.add(Calendar.DATE, -1);
    prevTime = tmpDay.getTime().getTime();
    tmpDay.add(Calendar.DATE  , 2);
    nextTime = tmpDay.getTime().getTime();
    title = StringUtil.getDateTimeFormatString(sec.getTimeZone(), BoxStatic.VERYLONG_DATE_FORMAT, currentDate.getTime());
  }


  String tmp = (String)session.getAttribute("resv.VIEW_MINE");
  if ( tmp != null && tmp.length() > 0 )
    VIEW_MINE = Integer.parseInt(tmp);
  tmp = (String)session.getAttribute("resv.RESOURCEID");
  if ( tmp != null && tmp.length() > 0 )
    RESOURCEID = Integer.parseInt(tmp);
  tmp = (String)session.getAttribute("resv.RESOURCECATID");
  if ( tmp != null && tmp.length() > 0 )
    RESOURCECATID = Integer.parseInt(tmp);
  tmp = (String)session.getAttribute("resv.SORTBY");
  if ( tmp != null && tmp.length() > 0 )
    SORTBY = tmp;

  boolean sortAsc = true;
  tmp = (String) session.getAttribute("resv.ASC");
  if (tmp!=null && tmp.length() > 0)
    sortAsc = new Boolean(tmp).booleanValue();
  else
    session.setAttribute("resv.ASC", "true");

  Calendar today = Calendar.getInstance(sec.getTimeZone());
  BoxReservation home = BoxReservation.getInstance();

  int workStartHour = sec.getConfigInt("calendar", "General", "Working Hour Start");
  int workEndHour = sec.getConfigInt("calendar", "General", "Working Hour End");
%>


<jsp:include page="/en/jsp/header.jsp" flush="true"/>

<script Language="JavaScript">
  function confirmDel(entry)
  {
    return confirm("Are you sure to delete " + entry);
  }

  function onChangeSubmit()
  {
    document.theForm.submit();
  }
  function onChangeResource()
  {
    document.theForm.RESOURCECATID.selectedIndex=0;
    document.theForm.submit();
  }
  function onChangeResourceCat()
  {
    document.theForm.RESOURCEID.selectedIndex=0;
    document.theForm.submit();
  }
  function onChangeFormat()
  {
    document.theForm.submit();
  }
</script>

<form name="theForm" method="POST" action="<%=BoxStatic.servletDir%>BoxReservationViewAction">

<table width="100%" height=26 align=middle border=0 cellpadding=0 cellspacing=0 bgcolor="#f4f4f4" style="font-size:16px;color:#d05000">
  <tr>
    <td>&nbsp;<img src="<%=BoxStatic.imageDir%>itemball.jpg" width=14 height=15 border=0 align="absmiddle">
      <b><%=boxName%> - Resource Reservation</b>
    </td>
    <td align=right>View: &nbsp;
      <a href="<%=BoxStatic.jspDir%>resource/BoxResource.jsp">
        Resources
      </a>&nbsp;|&nbsp;
      <a href="<%=BoxStatic.jspDir%>resource/BoxResourceCat.jsp">
        Resource Categories
      </a>&nbsp;|&nbsp;
      <a href="<%=BoxStatic.servletDir%>BoxReservationSettingsAction?SubmitEdit=edit">
        Settings
      </a>
    </td>
  </tr>
</table>

<hr width="100%" color=#E06000 align=left>

<TABLE WIDTH="100%" BORDER=0 CELLSPACING=0 CELLPADDING=0>
  <tr><td>
    <table width="100%">
      <tr>
        <td align=left>
          <input type="button" value="New Reservation" onclick="window.location='<%=BoxStatic.servletDir%>BoxReservationAction?SubmitEdit=Edit&ID=0'" >
        </td>
        <td align=middle>View
          <select name="VIEW_FORMAT" size="1" onchange="onChangeFormat()">
            <option <% if (VIEW_FORMAT.compareTo("day") == 0) out.print(" selected ");%> value="day">Daily</option>
            <option <% if (VIEW_FORMAT.compareTo("week") == 0) out.print(" selected ");%> value="week">Weekly</option>
           <option <% if (VIEW_FORMAT.compareTo("month") == 0) out.print(" selected ");%> value="month">Monthly</option>
          </select>
        </td>
        <td align=right>
          <table cellpadding="3" cellspacing="0" border="0" width="100%">
            <tr>
              <td align=left>
                <a href="<%=BoxStatic.servletDir%>BoxReservationViewAction?SubmitView=view&t=<%=prevTime%>">
                  <img SRC="<%=BoxStatic.imageDir%>cal_left.gif" WIDTH="11" HEIGHT="11" BORDER="0">Previous <%=VIEW_FORMAT%></a>
              </td>
              <td align="center">
                <font face="Arial,Helvetica" SIZE="+1"><b><%=title%></b></font>
              </td>
              <td align="right">
               <a href="<%=BoxStatic.servletDir%>BoxReservationViewAction?SubmitView=view&t=<%=nextTime%>">Next <%=VIEW_FORMAT%><img
              SRC="<%=BoxStatic.imageDir%>cal_right.gif" WIDTH="11" HEIGHT="11" BORDER="0"></a>
              </td>
            </tr>
          </table>
        </td>

      </tr>
      <tr>
        <td align=left>Show
          <select name="VIEW_MINE" size="1" onchange="onChangeSubmit()">
            <option <% if (VIEW_MINE != 0) out.print(" selected ");%> value="1">My Reservations</option>
            <option <% if (VIEW_MINE == 0) out.print(" selected ");%>  value="0">All Reservations</option>
          </select>
        </td>

        <td align=right colspan=2>Filter By: Resource
          <select name="RESOURCEID" size=1 onchange="onChangeResource()">
              <Resource:ResourceList selected="<%=RESOURCEID%>" allownull="true" />
          </select>
          Resource Category:
          <select name="RESOURCECATID" size=1 onchange="onChangeResourceCat()">
            <Resource:ResourceCatList selected="<%=RESOURCECATID%>" allownull="true" />
          </select>
        </td>
      </tr>
    </table>
  </td></tr>
  <tr><td>
<hr width=100% color=#f0f0f0 align=left>
  </td></tr>
  <tr><td>

<%if (VIEW_FORMAT.compareTo("week") == 0)
  { %>
    <%@include file="BoxReservationWeek.jsp" %>
<%}
  else if (VIEW_FORMAT.compareTo("month") == 0)
  { %>
    <%@include file="BoxReservationMonth.jsp" %>
<%}
  else
  { %>
    <%@include file="BoxReservationDay.jsp" %>
<%}%>

    </td></tr>
  </TABLE>
<hr width=100% color=#E06000 align=left>

</form>
<jsp:include page="/en/jsp/footer.jsp" flush="true"/>
